/*
 * @Author: your name
 * @Date: 2020-07-15 10:31:46
 * @LastEditTime: 2020-07-23 13:59:42
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /waibao/iuyun-device-web/wechat/src/daos/device_dao.js
 */

import request from "../config/request.js";
import host from "../config/host";

const loadDevice = function(params, callback) {
  request.postData(
    host.pcHostUrl + "/factory/device/loadDevices.json",
    params,
    callback
  );
};

//设备采集点类型列表
const transformRuleList = function(params, callback) {
  request.postData(host.pcHostUrl + "/transformRule/list", params, callback);
};

const loadDeviceData = function(deviceId, callback) {
  request.getData(
    host.pcHostUrl + "/wx/deviceDetailData/realTimeData/" + deviceId,
    callback
  );
};

/**
获取设备统计数据
*/
const deviceStatistics = function(deviceId, callback) {
  request.getData(
    host.pcHostUrl +
      "/wx/deviceDetailData/duringAndTimesStatistics/" +
      deviceId,
    callback
  );
};
//获取财务记录
const getFinacialList = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceRecord/page",
    data,
    callback
  );
};
//添加记录
const addFinancialRecord = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceRecord/add",
    data,
    callback
  );
};
//修改记录
const updateFinancialRecord = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceRecord/update",
    data,
    callback
  );
};
//获取财务记录详情
const getFinacialDetail = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceRecord/details",
    data,
    callback
  );
};
//废弃财务记录
const abandoned = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceRecord/abandoned",
    data,
    callback
  );
};
//工单财务记录
const getWorkOrderRecord = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceRecord/inWorkSheet",
    data,
    callback
  );
};
//设备下的所有工单
const getDeviceOrder = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceWorkSheet/list",
    data,
    callback
  );
};
//工单信息
const getOrderIdDetail = function(data, callback) {
  request.postData(
    host.pcHostUrl + "/wx/finance/deviceWorkSheet/info",
    data,
    callback
  );
};

//获取设备类型列表
const getAllDeviceTypeList = function(callback) {
  request.postData(host.hostUrl + "/deviceType/list", {}, callback);
};

const getDeviceList = function(params, success) {
  request.defaults({
    method: "post",
    url: host.pcHostUrl + "/wx/device/getDeviceList",
    params,
    success
  });
};

const getDeviceInfo = function(id, callback) {
  request.getData(`${host.pcHostUrl}/wx/device/getDeviceInfo/${id}`, callback);
};

const getDeviceNum = function(data, success) {
  request.defaults({
    method: "post",
    url: host.pcHostUrl + "/wx/device/getDeviceNum",
    data,
    success
  });
};
const getDeviceOrgNumList = function(params, success) {
  request.defaults({
    method: "post",
    url: host.pcHostUrl + "/wx/device/deviceStatistic",
    params,
    success
  });
};
const getDuringTimeStatistics = function(params, success) {
  request.defaults({
    method: "post",
    url: host.pcHostUrl + "/wx/device/duringTimeStatistics",
    params,
    success
  });
};
const getHappenTimesStatistics = function(params, success) {
  request.defaults({
    method: "post",
    url: host.pcHostUrl + "/wx/device/happenTimesStatistics",
    params,
    success
  });
};
const getChartDataDetail = function(data, success) {
  request.defaults({
    method: "post",
    url: host.pcHostUrl + "/wx/deviceDetailData/chartDataDetail",
    data,
    success
  });
};
const getQueryChartList = function(deviceId, success) {
  request.defaults({
    method: "get",
    url: `${host.pcHostUrl}/wx/deviceDetailData/queryChartList/${deviceId}`,
    success
  });
};

// 设备列表优化

const getDeviceDepList = function(data, callback) {
  request.postData(
    host.pcHostUrl + `/wx/device/queryDepartmentListByDepartmentId`,
    data,
    callback
  );
};

const getDeviceListByDep = function(data, callback) {
  request.postData(
    host.pcHostUrl + `/wx/device/getDeviceListByDepartment`,
    data,
    callback
  );
};

const getDeviceListDetailByDep = function(data, callback) {
  request.postData(host.pcHostUrl + `/wx/device/queryDevices`, data, callback);
};

// 更换详情
const getReplaceTaskRecordDetails = function(id, callback) {
  request.getData(
    host.pcHostUrl + `/wx/replaceTaskRecord/details/${id}`,
    callback
  );
};
// 更换详情
const getReplaceTaskRecordConfig = function(id, callback) {
  request.getData(
    host.pcHostUrl + `/wx/replaceTaskRecord/getConfig/${id}`,
    callback
  );
};

// 更换列表
const getReplaceTaskRecordDepartment = function(data, callback) {
  request.postData(
    host.pcHostUrl + `/wx/replaceTaskRecord/getReplaceTaskRecordDepartment`,
    data,
    callback
  );
};
// 更换列表
const getReplaceTaskRecordDepartmentDetails = function(data, callback) {
  request.postData(
    host.pcHostUrl + `/wx/replaceTaskRecord/getReplaceTaskRecordDetails`,
    data,
    callback
  );
};

// 更换列表
const getReplaceTaskRecordDevice = function(data, callback) {
  request.postData(
    host.pcHostUrl + `/wx/replaceTaskRecord/getReplaceTaskRecordDevice`,
    data,
    callback
  );
};
// 更换列表
const postReplaceTaskRecordReplace = function(data, callback) {
  request.postData(
    host.pcHostUrl + `/wx/replaceTaskRecord/replace`,
    data,
    callback
  );
};

const doFollow = (deviceId, callback)=>{
  request.getData(
    host.pcHostUrl + `/wx/device/doFollow?deviceId=`+deviceId,
    {},
    callback
  )
}

const disFollow = (deviceId, callback)=>{
  request.getData(
    host.pcHostUrl + `/wx/device/disFollow?deviceId=`+deviceId,
    {},
    callback
  )
}

export default {
  loadDevice,
  transformRuleList,
  loadDeviceData,
  deviceStatistics,
  getFinacialList,
  addFinancialRecord,
  getFinacialDetail,
  abandoned,
  updateFinancialRecord,
  getWorkOrderRecord,
  getDeviceOrder,
  getOrderIdDetail,
  getAllDeviceTypeList,
  getDeviceNum,
  getDeviceList,
  getDeviceInfo,
  getDeviceOrgNumList,
  getDuringTimeStatistics,
  getHappenTimesStatistics,
  getChartDataDetail,
  getQueryChartList,
  getReplaceTaskRecordDetails,
  getReplaceTaskRecordConfig,
  getReplaceTaskRecordDepartment,
  getReplaceTaskRecordDepartmentDetails,
  getReplaceTaskRecordDevice,
  postReplaceTaskRecordReplace,
  getDeviceDepList,
  getDeviceListByDep,
  getDeviceListDetailByDep,
  doFollow,
  disFollow,
};
